<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>社区商品</title>
    <script type="text/javascript" src="__PUBLIC__/V3/layer/layer.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/V1/plugins/layui/css/layui.css" media="all">
    <script src="__PUBLIC__/V1/plugins/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__PUBLIC__/V3/js/jquery-1.7.1.js"></script>
</head>
<body>

<div style="margin-top: 20px">
    <form class="layui-form" id="goods_category_form">
        <input  type="hidden" name="id" value="<?php echo isset($goods_category_relation->id)?$goods_category_relation->id:'0' ?>">
        <input  type="hidden" name="category_id" value="{$category_id}">
        <div class="layui-inline">
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-block">
                    <input type="text" id="search_goods" placeholder="请输入搜索商品" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="submit_seach_goods">筛选</button>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">专题商品</label>
            <div class="layui-input-block">
                <select name="goods_id" lay-filter="goods_list">
                    {volist name="goods_list" id="val"}
                    <option value="{$val->goods_id}" stock="{$val->stock}" <?php echo isset($goods_category_relation->goods_id)&&$goods_category_relation->goods_id==$val->goods_id?"selected":"" ?> >
                    {$val->name."--价格:".$val->price."--库存".$val->stock}
                    </option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submit_">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form()
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

        form.on('submit(submit_seach_goods)', function (data)
        {
            $search_goods = $('#search_goods').val();
            $.ajax({
                url:"/admin/community_goods/get_search_goods",
                dataType:"json",
                async:true,
                data:{"search_goods":$search_goods},
                type:"POST",
                success:function(data){
                    if (data.code == 0)
                    {
                        var html = "";
                        if(data.data == "")
                        {
                            html += "<option value='0'>无对应商品</option>";
                        }
                        else
                        {
                            $.each(data.data, function (k, v)
                            {
                                html += "<option value='" + v.goods_id + "'>" + v.name + "</option>";
                            });
                        }
                        $("select[lay-filter='goods_list']").html(html);
                        form.render('select');
                    }
                }
            });
            return false;
        });

        form.on('submit(submit_)', function (data) {
            $.ajax({
                url: "/admin/community_goods/category_goods_relation_operation",
                dataType: "json",
                async: true,
                data: $("#goods_category_form").serialize(),
                type: "POST",
                success: function (res)
                {
                    if (res.code == 0)
                    {
                        layer.alert(res.data, {icon: 1});
                    }
                    else
                    {
                        layer.alert(res.data, {icon: 5});
                    }
                }
            });
            return false;
        });
    });
</script>